package serial.usb

import serial.toU8

object Proto {

    const val HEAD0 = 0xE1
    const val HEAD1 = 0x1E

    const val END = 0xEF

    const val MIN_LEN = 7
}

class PackageException(msg: String) : Exception(msg)


fun xorSum(buf: ByteArray, offset: Int, len: Int): Int {
    var s = 0
    for (i in 0 until len) {
        s = s xor buf[offset + i].toU8()
    }
    return s
}
